package com.spring.boot.web;

import com.spring.boot.constants.CommonConstants;
import com.spring.boot.entity.Area;
import com.spring.boot.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhengzihong
 * @date 2018/2/23
 */
@RestController
@RequestMapping("/superAdmin")
public class AreaController {

    @Autowired
    private AreaService areaService;

    /**
     * 查询区域信息列表
     * @return
     */
    @RequestMapping(value = "/listArea", method = RequestMethod.GET)
    private Map<String, Object> listArea() {
        Map<String, Object> map = new HashMap<String, Object>();
        List<Area> list = areaService.queryArea();
        map.put("areaList", list);
        return map;

    }


    /**
     * 获取区域信息
     * @param areaId
     * @return
     */
    @RequestMapping(value = "/getAreaById", method = RequestMethod.GET)
    private Map<String, Object> getAreaById(Integer areaId) {
        Map<String, Object> map = new HashMap<String, Object>();
        Area area = areaService.queryAreaById(areaId);
        map.put("area", area);
        return map;
    }

    /**
     * 添加区域信息
     * @param area
     * @return
     */
    @RequestMapping(value = "/addArea",method = RequestMethod.POST)
    private Map<String,Object> addArea(@RequestBody Area area){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put(CommonConstants.SUCCESS,areaService.insertArea(area));
        return map;
    }

    /**
     * 更新区域信息
     * @param area
     * @return
     */
    @RequestMapping(value = "/updateArea",method = RequestMethod.POST)
    private Map<String,Object> updateArea(@RequestBody Area area){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put(CommonConstants.SUCCESS,areaService.updateArea(area));
        return map;
    }

    /**
     * 删除区域信息
     * @param areaId
     * @return
     */
    @RequestMapping(value = "/deleteArea",method = RequestMethod.GET)
    private Map<String,Object> deleteArea(Integer areaId){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put(CommonConstants.SUCCESS,areaService.deleteArea(areaId));
        return map;
    }


}










